// @ts-nocheck
export {
  arrayRemoveZero, // 地图数组降维
  deepClone,
  getCoordinatesCenter, // 获得 中心
  getKeyValue,
  getSvgUrl,
  isLongitudeLatitudeArray,
  randomNum,
  randomString,
  toChineseNumber,
  heightToZoom,
  zoomToheight
};

// 地图数组降维
function arrayRemoveZero(array) {
  if (Array.isArray(array) && array.length == 1) {
    return arrayRemoveZero(array[0]);
  } else {
    return array;
  }
}

// 深拷贝 数据
function deepClone(data) {
  // string,number,bool,null,undefined,symbol
  // object,array,date
  if (data && typeof data === 'object') {
    // 针对函数的拷贝
    if (typeof data === 'function') {
      let tempFunc = data.bind(null);
      tempFunc.prototype = deepClone(data.prototype);
      return tempFunc;
    }

    switch (Object.prototype.toString.call(data)) {
      case '[object String]':
        return data.toString();
      case '[object Number]':
        return Number(data.toString());
      case '[object Boolean]':
        return new Boolean(data.toString());
      case '[object Date]':
        return new Date(data.getTime());
      case '[object Array]':
        var arr = [];
        for (let i = 0; i < data.length; i++) {
          arr[i] = deepClone(data[i]);
        }
        return arr;

      // js自带对象或用户自定义类实例
      case '[object Object]':
        var obj = {};
        for (let key in data) {
          // 会遍历原型链上的属性方法，可以用hasOwnProperty来控制 （obj.hasOwnProperty(prop)
          obj[key] = deepClone(data[key]);
        }
        return obj;
    }
  } else {
    // string,number,bool,null,undefined,symbol
    return data;
  }
}

// 获得 中心
function getCoordinatesCenter(coordinates) {
  // 点 圆形操作
  if (coordinates.length == 2 && coordinates[0][0] == null) {
    return coordinates;
  }
  // 面环操作
  if (isLongitudeLatitudeArray(coordinates[0][0])) {
    coordinates = deepClone(coordinates[0]);
  }
  if (
    coordinates[0][0] == coordinates[coordinates.length - 1][0] &&
    coordinates[0][1] == coordinates[coordinates.length - 1][1]
  ) {
    // 去除面重复数组
    // debugConsole.log('coordinates', coordinates);
    coordinates = deepClone(coordinates);
    coordinates.pop();
    // debugConsole.log('coordinates', coordinates);
  }
  let longitude = 0.0;
  let latitude = 0.0;
  let count = 0.0;
  for (let i = 0; i < coordinates.length; i++) {
    if (isLongitudeLatitudeArray(coordinates[i])) {
      longitude += coordinates[i][0];
      latitude += coordinates[i][1];
      count++;
    }
  }
  return [longitude / count, latitude / count];
}

async function getKeyValue(object, self, masterName = 'vick2dMap') {
  if (object.key == 'editLayerObject') {
    // console.log('getKeyValue editLayerObject', object);
    let editLayerObject = object.value;
    if (editLayerObject.properties.longitude == null || editLayerObject.properties.latitude == null) {
      let center = getCoordinatesCenter(editLayerObject.coordinates);
      editLayerObject.properties.longitude = center[0];
      editLayerObject.properties.latitude = center[1];
    }
    let messageObject = {};
    messageObject.editLayerObject = editLayerObject;
    let positionObject = await self[masterName + 'PostMessage']({
      from: masterName + 'Father',
      type: 'function',
      key: 'cameraPositionGet'
    });
    messageObject.positionObject = positionObject;
    let X = (editLayerObject.properties.longitude - positionObject.west) / (positionObject.east - positionObject.west);
    let Y = (editLayerObject.properties.latitude - positionObject.south) / (positionObject.north - positionObject.south);
    messageObject.XY = {
      X,
      Y
    };
    self.setState({
      messageObject: messageObject
    });
  } else if (object.key == 'editLayerClusterPointValueGet') {
    // console.log('getKeyValue editLayerClusterPointValueGet', object);
    let messageObject = {
      editLayerClusterPointValue: object.value
    };
    self.setState({
      messageObject: messageObject
    });
  } else if (object.key == 'cameraPositionGet') {
    // console.log('getKeyValue cameraPositionGet', object);
  }
}

// 获取svg图片路径
function getSvgUrl(name, { color = '#ffffff', width = '16', height = '16' } = {}) {
  let svgString;
  if (name == 'car') {
    svgString = `
    <svg t="1711443479174" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1098" width="${width}" height="${height}">
      <path d="M751.83441 384.567738c-11.294996-8.267061-24.592016-9.651545-35.110108-8.884601-0.209167-129.673333-0.816746-215.45156-1.284881-241.009726-0.408373-20.538168-1.792857-59.443156-29.213602-87.322076-2.569761-2.569761-7.798926-7.181387-17.350868-13.655591C628.944051 6.603688 585.258112 4.183332 559.431017 5.368609H512v0.209167h-47.241771C438.941094 4.392499 395.255155 6.812855 355.314295 33.91487c-9.551941 6.464244-14.781107 11.08583-17.350868 13.655591-27.410785 27.86896-28.795269 66.783908-29.213602 87.322077-0.458174 25.568127-1.075714 111.346354-1.284881 241.009726-10.528052-0.766944-23.815112 0.617539-35.110108 8.884601-11.862734 8.775037-20.119835 24.283246-16.78313 28.028324 2.460198 2.818769 10.46829-1.90242 25.209556-6.98218 9.800949-3.436308 18.834954-5.6973 26.693643-7.29095-0.149405 128.747024 0.099603 296.86717 1.185277 490.087308 0.099603 14.731305 3.127539 29.363007 9.392577 42.709828 4.571784 9.701346 10.826862 20.329002 19.402692 30.956657 6.98218 8.675434 21.145747 25.876897 46.195938 38.496616 20.787176 10.528052 39.831297 13.247218 51.435063 14.014162h77.102794v-0.209167h76.913548c11.603766-0.766944 30.647887-3.48611 51.435063-14.014162 25.050191-12.629679 39.223718-29.821181 46.195938-38.496615a153.381869 153.381869 0 0 0 19.402692-30.956657c6.265038-13.346821 9.292973-27.978523 9.392577-42.709828 1.075714-193.220139 1.334682-361.340285 1.185277-490.087309 7.858688 1.59365 16.892693 3.854642 26.693643 7.290951 14.731305 5.07976 22.739398 9.800949 25.209555 6.98218 3.336705-3.755039-4.920395-19.263248-16.783129-28.038285z" fill="${color}" p-id="1099"></path>
      <path d="M569.570617 5.129562c26.215547 0 64.214147 4.75107 99.304334 28.566182 9.551941 6.464244 14.781107 11.08583 17.350868 13.655591 27.410785 27.86896 28.795269 66.783908 29.213602 87.322076 0.458174 25.568127 1.075714 111.346354 1.284881 241.009726 1.613571-0.119524 3.286904-0.189246 5.000077-0.189245 9.541981 0 20.538168 2.061785 30.110031 9.063886 11.862734 8.775037 20.119835 24.283246 16.783129 28.028324-0.507976 0.587659-1.26496 0.846627-2.260991 0.846627-3.8148 0-11.265116-3.80484-22.938604-7.828807-9.800949-3.436308-18.834954-5.6973-26.693642-7.29095 0.149405 128.747024-0.099603 296.86717-1.185278 490.087308-0.099603 14.731305-3.127539 29.363007-9.392576 42.709828a153.381869 153.381869 0 0 1-19.402693 30.956657c-6.98218 8.675434-21.145747 25.876897-46.195938 38.496615-20.787176 10.528052-39.831297 13.247218-51.435063 14.014163H512.199206v0.209166h-77.102793c-11.603766-0.766944-30.647887-3.48611-51.435064-14.014162-25.050191-12.629679-39.223718-29.821181-46.195938-38.496615a153.381869 153.381869 0 0 1-19.402692-30.956657c-6.265038-13.346821-9.292973-27.978523-9.392577-42.709828-1.075714-193.220139-1.334682-361.340285-1.185277-490.087309-7.858688 1.59365-16.892693 3.854642-26.693643 7.29095-11.673488 4.023967-19.123804 7.828807-22.938604 7.828808-0.996031 0-1.753015-0.258968-2.260991-0.846627-3.336705-3.745078 4.930356-19.253288 16.78313-28.028325 9.561902-7.002101 20.568049-9.063886 30.11003-9.063886 1.723134 0 3.396467 0.069722 5.010038 0.189246 0.209167-129.673333 0.816746-215.45156 1.284881-241.009727 0.408373-20.538168 1.792857-59.443156 29.213602-87.322076 2.569761-2.569761 7.798926-7.191347 17.350868-13.655591 35.070267-23.805151 73.068866-28.556221 99.284413-28.556221 3.615594 0 7.002101 0.089643 10.12964 0.229087H512v-0.209167h47.431017c3.137499-0.139444 6.524006-0.239048 10.1396-0.239047m0-5.129562v5.129562-5.129562c-3.416388 0-6.902498 0.079683-10.368687 0.239048L512 0.229087h-5.129562v0.209167h-42.112209a222.712629 222.712629 0 0 0-10.12964-0.229087c-39.014551 0-73.387596 9.910513-102.192825 29.452649-9.800949 6.64353-15.249241 11.424481-18.097891 14.273131-29.492491 29.990507-30.349078 72.640573-30.70765 90.848027-0.468135 25.996421-1.065754 110.649132-1.27492 235.800483-12.818925 0.019921-23.924675 3.406428-33.018442 10.059917-9.940394 7.360672-18.70547 20.070033-19.562057 28.366975-0.378492 3.705237 0.866547 5.976189 1.972142 7.221228 1.005992 1.145436 2.908412 2.569761 6.095712 2.569761 3.356626 0 7.370633-1.563769 13.446425-3.944284 3.237102-1.26496 6.892538-2.689285 11.165512-4.163411 6.454284-2.260991 12.99821-4.163411 19.880787-5.767023-0.109563 105.041475 0.00996 272.454439 1.185278 483.742589 0.109563 16.036106 3.436308 31.125982 9.880632 44.861256a158.367006 158.367006 0 0 0 20.060073 31.992529c6.364641 7.90849 21.285192 26.454595 47.889191 39.861178 16.603844 8.406505 34.582212 13.30698 53.407206 14.55202l0.169325 0.00996h82.401681v-0.209167h71.943351l0.169325-0.00996c18.834954-1.255 36.803362-6.145514 53.417166-14.552019 26.594039-13.406583 41.51459-31.942728 47.879231-39.861178 7.948331-9.850751 14.691464-20.617851 20.050113-31.98257 6.444323-13.735274 9.771068-28.83511 9.880632-44.861256 1.175317-211.198506 1.304801-378.651311 1.185278-483.752548 6.882577 1.603611 13.426504 3.506031 19.850906 5.757062 4.292895 1.484087 7.958291 2.908412 11.185433 4.173371 6.075792 2.370555 10.099759 3.944284 13.456385 3.944285 3.187301 0 5.089721-1.414365 6.125593-2.609603 1.075714-1.205198 2.320753-3.47615 1.942261-7.181386-0.856587-8.286982-9.621664-21.006303-19.542136-28.347055-9.113688-6.673411-20.219438-10.049957-33.038363-10.069878-0.209167-125.121469-0.806785-209.794102-1.27492-235.790522-0.368532-18.217415-1.215158-60.867481-30.677769-90.828107-2.878531-2.878531-8.326823-7.659482-18.127772-14.303011C642.958213 9.910513 608.585168 0 569.570617 0z" fill="${color}" opacity=".6" p-id="1100"></path>
      <path d="M361.957824 564.570539c3.257023 131.954245 0.766944 272.79309 0 312.345499-6.693331-7.848728-19.153685-18.864835-25.548206-33.24753-12.848806-28.894872-12.091822-55.558634-11.553965-64.752003 2.619563-44.263637 1.57373-206.955412 0-433.652168a701.3396 701.3396 0 0 1 24.502374 92.750448c10.538013 54.861412 11.882655 97.411875 12.599797 126.555754z" fill="#5A6569" p-id="1101"></path>
      <path d="M324.855653 345.254377a701.3396 701.3396 0 0 1 24.502374 92.750448c10.538013 54.871372 11.882655 97.421835 12.599797 126.555754 3.257023 131.954245 0.766944 272.79309 0 312.345498-6.693331-7.848728-19.153685-18.864835-25.548206-33.247529-12.848806-28.894872-12.091822-55.558634-11.553965-64.752004 2.619563-44.263637 1.58369-206.955412 0-433.652167m-5.348689-31.763442l0.219127 31.803283c1.444246 208.140689 2.699245 387.894483 0.009961 433.313517-1.354603 22.868882 2.908412 46.713874 11.982258 67.142479 5.259046 11.842814 14.014162 21.185589 21.046144 28.695666 1.962182 2.091666 3.8148 4.073769 5.288927 5.806863l8.775037 10.279044 0.258968-13.506186c1.27492-65.26994 2.958213-192.662361 0-312.574586-0.64742-26.325111-1.733095-70.379581-12.68944-127.402381a707.658423 707.658423 0 0 0-24.681659-93.427748l-10.209323-30.129951z" fill="${color}" opacity=".6" p-id="1102"></path>
      <path d="M413.064197 41.803439c-10.986227-9.800949-66.744067 18.546105-63.69621 44.801494 1.364563 11.802973 14.611781 23.157731 26.604 23.097969 26.992452-0.129484 47.978834-58.178196 37.09221-67.899463z" fill="#BFC8D1" p-id="1103"></path>
      <path d="M361.957824 876.916038c-6.723212-7.858688-19.143724-18.834954-25.568127-33.26745-12.828885-28.84507-12.061941-55.538713-11.553964-64.732083 1.484087-25.408762 1.792857-89.832075 1.484086-183.000856l36.803362 33.984592c1.304801 110.210879-0.498016 214.007315-1.165357 247.015797zM598.535211 908.898607c-29.283324 2.679325-57.490935 2.270952-86.535211 2.360595v0.209166c-28.974555-0.079683-57.122403 0.30877-86.345965-2.360594-18.038129-1.653412-35.887013-3.406428-53.54665-5.249086 0.368532 7.978212 2.599642 34.791378 23.625865 58.277799 25.578087 28.566182 59.702124 30.697689 66.146448 30.976578h50.329469v-0.219127h50.100381c6.444323-0.278889 40.578321-2.410396 66.146448-30.976577 21.026224-23.486421 23.257334-50.299588 23.625865-58.2778-17.659637 1.852618-35.508521 3.605634-53.54665 5.259046z" fill="#303E41" p-id="1104"></path>
      <path d="M652.091822 903.649521c-0.368532 7.978212-2.599642 34.791378-23.625866 58.2778-25.578087 28.566182-59.702124 30.697689-66.146448 30.976578h-50.100381v0.219126h-50.329469c-6.444323-0.278889-40.578321-2.410396-66.146447-30.976577-21.026224-23.486421-23.257334-50.299588-23.625866-58.2778 17.659637 1.852618 35.508521 3.595673 53.54665 5.249086 29.213602 2.669364 57.36145 2.280912 86.345965 2.360595v-0.209167c29.044277-0.089643 57.251887 0.31873 86.535212-2.360595 18.028169-1.663373 35.877052-3.416388 53.54665-5.259046m5.39849-5.72718l-5.936347 0.617539a4083.63925 4083.63925 0 0 1-53.486889 5.239126c-25.04023 2.290872-48.905144 2.310793-74.1645 2.320753-3.964205 0-7.92841 0.00996-11.912536 0.01992l-5.119602 0.019921v0.189246c-2.191269 0-4.382538 0-6.573807-0.00996-25.269318-0.019921-49.134231-0.029881-74.164501-2.320754-17.779161-1.623531-35.767489-3.386507-53.486888-5.239125l-5.936348-0.617539 0.278889 5.966228c0.607579 13.237258 4.661427 38.825305 24.930667 61.4651 25.627889 28.615983 59.861489 32.251498 69.752081 32.679791l50.558556 0.009961h5.129562v-0.219127h44.960859c10.109719-0.438254 44.35328-4.063808 69.971209-32.679792 20.26924-22.639795 24.323088-48.227842 24.930667-61.4651l0.268928-5.976188z" fill="${color}" opacity=".6" p-id="1105"></path>
      <path d="M662.241382 564.351412c-3.257023 131.954245-0.766944 272.79309 0 312.345499 6.693331-7.848728 19.153685-18.864835 25.548206-33.24753 12.848806-28.894872 12.091822-55.558634 11.553965-64.752003-2.619563-44.263637-1.57373-206.955412 0-433.652168a701.3396 701.3396 0 0 0-24.502373 92.750448c-10.538013 54.861412-11.882655 97.421835-12.599798 126.555754z" fill="#5A6569" p-id="1106"></path>
      <path d="M699.343553 345.04521c-1.57373 226.696755-2.619563 389.38853 0 433.652168 0.547817 9.19337 1.294841 35.857132-11.553965 64.752003-6.394522 14.392654-18.854875 25.408762-25.548206 33.24753-0.766944-39.562369-3.257023-180.391254 0-312.345499 0.717143-29.13392 2.061785-71.694343 12.599798-126.555754 7.60968-39.652012 17.311026-71.574819 24.502373-92.750448m5.348689-31.773402l-10.219283 30.11999a707.658423 707.658423 0 0 0-24.681659 93.427749c-10.956346 57.0228-12.04202 101.07727-12.68944 127.402381-2.958213 119.912225-1.27492 247.304646 0 312.574586l0.258968 13.506186 8.775037-10.279044c1.474127-1.733095 3.326745-3.715197 5.288927-5.806864 7.031982-7.510077 15.787098-16.852852 21.046144-28.695665 9.083807-20.428605 13.336861-44.273597 11.982258-67.142479-2.689285-45.419034-1.434285-225.172827 0.009961-433.313517l0.229087-31.793323z" fill="${color}" opacity=".6" p-id="1107"></path>
      <path d="M611.135009 41.594273c10.986227-9.800949 66.744067 18.546105 63.69621 44.801494-1.364563 11.802973-14.611781 23.157731-26.603999 23.097969-26.992452-0.129484-47.988795-58.178196-37.092211-67.899463z" fill="#BFC8D1" p-id="1108"></path>
      <path d="M662.241382 876.696911c6.723212-7.858688 19.143724-18.834954 25.568127-33.26745 12.828885-28.84507 12.061941-55.538713 11.553965-64.732083-1.484087-25.408762-1.792857-89.832075-1.484087-183.000856l-36.803362 33.984592c-1.304801 110.210879 0.498016 214.007315 1.165357 247.015797z" fill="#303E41" p-id="1109"></path>
      <path d="M652.091822 903.749125c-0.358571 7.958291-2.619563 34.801338-23.615906 58.267839-25.617929 28.596063-59.702124 30.697689-66.166368 31.006458h-11.603766l-84.602911-81.724379c15.249241 0.30877 30.438721 0.209167 45.897129 0.258968v-0.209167c29.054237-0.049802 57.241927 0.30877 86.545172-2.360594 18.018209-1.653412 35.887013-3.396467 53.54665-5.239125z" fill="#5A6569" p-id="1110"></path>
      <path d="M666.265349 298.321376c-4.980157-10.259124-14.332892-20.787176-37.271496-31.504475-42.918995-20.040153-89.194615-20.060073-117.003813-17.848883v0.199206c-27.839079-2.191269-73.965295-2.111587-116.774726 17.868804-22.948564 10.707338-32.3013 21.245351-37.271496 31.504475-6.782974 13.984281-5.498094 27.58011-3.675356 40.946852 3.137499 23.038207 6.274998 56.763832 19.950509 98.696755h138.010116v-0.219127h137.771069c13.675512-41.932924 16.813011-75.668508 19.950509-98.696755 1.812777-13.366742 3.097658-26.962571-3.685316-40.946852z" fill="#303E41" p-id="1111"></path>
      <path d="M535.815112 248.001868c26.783285 0 60.917283 3.755039 93.16878 18.815033 22.948564 10.707338 32.3013 21.245351 37.271497 31.504475 6.782974 13.984281 5.498094 27.58011 3.675356 40.946852-3.137499 23.038207-6.274998 56.763832-19.95051 98.696755H512.209167v0.219127H374.199051c-13.675512-41.932924-16.813011-75.668508-19.95051-98.696755-1.822738-13.366742-3.107618-26.962571 3.675356-40.946852 4.980157-10.259124 14.332892-20.787176 37.271496-31.504475 32.251498-15.050035 66.385495-18.815034 93.158821-18.805073 8.765077 0 16.743288 0.398413 23.605945 0.94623v-0.199207c6.932379-0.557778 14.990273-0.976111 23.854953-0.97611m0-5.129562c-7.92841 0-16.085908 0.32869-24.243406 0.97611l-0.876507 0.069723c-7.520037-0.547817-15.020154-0.826706-22.331025-0.826706-35.837211 0-67.909423 6.494125-95.330169 19.293129-20.807097 9.711307-33.058283 20.169637-39.721734 33.91487-7.30091 15.040075-6.125593 29.343086-4.14349 43.885145 0.398413 2.908412 0.796825 5.996109 1.215158 9.243172 2.888491 22.49039 6.852696 53.287682 18.944518 90.350011l1.155396 3.545872H517.348689v-0.219127h136.366664l1.155396-3.545871c12.091822-37.07229 16.056027-67.869582 18.944518-90.350012 0.418333-3.247062 0.816746-6.33476 1.215159-9.243172 1.982103-14.542059 3.15742-28.84507-4.143491-43.885145-6.66345-13.745234-18.914637-24.203564-39.721734-33.91487-27.430706-12.799004-59.512878-19.293129-95.350089-19.293129z" fill="#EEEEEE" opacity=".6" p-id="1112"></path>
      <path d="M669.920784 339.248308c-3.127539 23.048167-6.265038 56.773792-19.920628 98.716675h-51.594429L424.389075 256.398413c21.125827-5.866625 43.128161-8.257101 65.030892-8.177419 24.293207 0.089643 49.004747-1.334682 73.18839 1.105595 22.848961 2.300833 45.548518 7.749125 66.395456 17.500273 22.948564 10.727259 32.291339 21.255311 37.271496 31.514434 6.773014 13.9544 5.488133 27.56019 3.645475 40.907012z" fill="#5A6569" p-id="1113"></path>
    </svg>
    `;
  } else {
    svgString = `
      <svg t="1660202311343" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="15088" width="${width}" height="${height}">
        <defs>
          <style type="text/css">@font-face { font-family: feedback-iconfont; src: url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.woff2?t=1630033759944") format("woff2"), url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.woff?t=1630033759944") format("woff"), url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.ttf?t=1630033759944") format("truetype"); }
          </style>
        </defs>
        <path d="M513.024 65.536q93.184 0 175.616 35.84t143.872 97.28 97.28 143.872 35.84 175.616q0 94.208-35.84 176.64t-97.28 143.872-143.872 97.28-175.616 35.84q-94.208 0-176.64-35.84t-143.872-97.28-97.28-143.872-35.84-176.64q0-93.184 35.84-175.616t97.28-143.872 143.872-97.28 176.64-35.84zM513.024 909.312q80.896 0 152.064-30.72t124.416-83.968 83.968-124.416 30.72-152.064-30.72-152.064-83.968-124.416-124.416-83.968-152.064-30.72q-81.92 0-153.088 30.72t-124.416 83.968-83.968 124.416-30.72 152.064 30.72 152.064 83.968 124.416 124.416 83.968 153.088 30.72zM513.024 190.464q66.56 0 124.928 25.088t102.4 69.12 69.12 102.4 25.088 124.928-25.088 125.44-69.12 102.912-102.4 69.12-124.928 25.088-125.44-25.088-102.912-69.12-69.12-102.912-25.088-125.44 25.088-124.928 69.12-102.4 102.912-69.12 125.44-25.088z" p-id="15089" fill="${color}"></path>
      </svg>
    `;
  }
  return `data:image/svg+xml;base64,${window.btoa(svgString)}`;
}

// 判断是否为 coordinate 经纬度坐标
function isLongitudeLatitudeArray(array) {
  if (Array.isArray(array) && array.length == 2 && typeof array[0] === 'number' && typeof array[1] === 'number') {
    return true;
  } else {
    return false;
  }
}

function randomNum(maxNum, minNum, decimalNum) {
  // 获取指定范围内的随机数, decimalNum指小数保留多少位
  let max = 0;
  let min = 0;
  switch (arguments.length) {
    case 1:
      return Math.floor(Math.random() * (maxNum + 1));
      break;
    case 2:
      minNum <= maxNum ? ((min = minNum), (max = maxNum)) : ((min = maxNum), (max = minNum));
      return Math.floor(Math.random() * (max - min + 1) + min);
      break;
    case 3:
      minNum <= maxNum ? ((min = minNum), (max = maxNum)) : ((min = maxNum), (max = minNum));
      return parseFloat((Math.random() * (max - min) + min).toFixed(decimalNum));
      break;
    default:
      return Math.random();
      break;
  }
}

function randomString(length, chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
  let result = '';
  for (let i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
  return result;
}

function toChineseNumber(num) {
  num = Number(num);
  var upperCaseNumber = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '百', '千', '万', '亿'];
  var length = String(num).length;
  if (length == 1) {
    return upperCaseNumber[num];
  } else if (length == 2) {
    if (num == 10) {
      return upperCaseNumber[num];
    } else if (num > 10 && num < 20) {
      return '十' + upperCaseNumber[String(num).charAt(1)];
    } else {
      return upperCaseNumber[String(num).charAt(0)] + '十' + upperCaseNumber[String(num).charAt(1)].replace('零', '');
    }
  }
}

// height to zoom
function heightToZoom(height) {
  const A = 40487.57;
  const B = 0.00007096758;
  const C = 91610.74;
  const D = -40467.74;
  return D + (A - D) / (1 + Math.pow(height / C, B));
}

// zoom to height
function zoomToheight(zoom) {
  const A = 40487.57;
  const B = 0.00007096758;
  const C = 91610.74;
  const D = -40467.74;
  return C * Math.pow((A - D) / (zoom - D) - 1, 1 / B);
}
